import {
  ADD_COUNTER,
  ADD_TO_CART,
  CHECK_OUT,
  SAVA_USER_INFO
} from './mutation-types'

export default {
  //mutations唯一的目的就是修改state的状态
  //mutations中的每个方法尽可能完成的事情比较单一一点
  //增加数量
  [ADD_COUNTER] (state, payload) {
    payload.count++
  },

  //增加商品
  [ADD_TO_CART] (state, payload) {
    payload.checked = true
    state.cartList.push(payload)
  },
  //结算商品
  [CHECK_OUT] (state, payload) {
    state.cartList = payload.arr

    state.orders = [...state.orders, payload.orders]
  },

  //登录成功将用户信息保存在state里面
  [SAVA_USER_INFO] (state, payload) {
    state.user = payload
  }
}
